package com.njtcedu.microblog.common.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "message", schema = "microblog")
public class Message implements Serializable{

	@Id
	@GeneratedValue
	@Column(name = "id")
	private Integer id;

	@Column(name = "message_content", length = 140, nullable = true)
	private String messageContent;

	@ManyToOne(cascade = CascadeType.REFRESH, optional = false)
	@JoinColumn(name = "send_user", nullable = false)
	private User sendUser;

	@ManyToOne(cascade = CascadeType.REFRESH, optional = false)
	@JoinColumn(name = "receivied_user", nullable = false)
	private User receiviedUser;

	@Column(name = "send_date")
	@Temporal(TemporalType.TIMESTAMP)
	private Date sendDate;

	@Column(name = "isRead")
	private boolean isRead;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getMessageContent() {
		return messageContent;
	}

	public void setMessageContent(String messageContent) {
		this.messageContent = messageContent;
	}

	public User getSendUser() {
		return sendUser;
	}

	public void setSendUser(User sendUser) {
		this.sendUser = sendUser;
	}

	public User getReceiviedUser() {
		return receiviedUser;
	}

	public void setReceiviedUser(User receiviedUser) {
		this.receiviedUser = receiviedUser;
	}

	public Date getSendDate() {
		return sendDate;
	}

	public void setSendDate(Date sendDate) {
		this.sendDate = sendDate;
	}

	public boolean isRead() {
		return isRead;
	}

	public void setRead(boolean isRead) {
		this.isRead = isRead;
	}

	@Override
	public int hashCode() {
		return id != null ? id.hashCode() : 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null || getClass() != obj.getClass())
			return false;
		Message message = (Message) obj;
		return id != null ? id.equals(message.id) : message.id == null;
	}

	@Override
	public String toString() {
		return "Message [id=" + id + ", messageContent=" + messageContent
				+ ", sendUser=" + sendUser + ", receiviedUser=" + receiviedUser
				+ ", sendDate=" + sendDate + ", isRead=" + isRead + "]";
	}

}
